package com.muyan.mqconfig;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

/**
 * @Author: YLTDMenglc
 * @Date: 2019/6/20
 * @Time: 13:50
 * @Description: 发布订阅模式 配置的交换机类型为 fanout
 */
@Component
public class FanoutConfig {

    private String FANOUT_EMAIL_QUEUE = "new_fanout_email_queue";

    private String FANOUT_SMS_QUEUE = "new_fanout_sms_queue";

    private String EXCHANGE_NAME = "fanoutExchange";

    @Bean
    public Queue fanoutEmailQueue(){
        return new Queue(FANOUT_EMAIL_QUEUE);
    }

    @Bean
    public Queue fanoutSMSQueue(){
        return new Queue(FANOUT_SMS_QUEUE);
    }

    @Bean
    public FanoutExchange fanoutExchange(){
        return new FanoutExchange(EXCHANGE_NAME);
    }

    @Bean
    Binding bindingExchangeEmail(Queue fanoutEmailQueue,FanoutExchange fanoutExchange){
        return BindingBuilder.bind(fanoutEmailQueue).to(fanoutExchange);
    }

    @Bean
    Binding bindingExchangeSms(Queue fanoutSMSQueue,FanoutExchange fanoutExchange){
        return BindingBuilder.bind(fanoutSMSQueue).to(fanoutExchange);
    }
}
